package hzau.utils;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import hzau.dao.PaperDao;
import hzau.pojo.Paper;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.Calendar;

@Component
//@SpringBootTest
public class Task {
//    @Autowired
    ESUtil esUtil =new ESUtil();
    @Autowired
    PaperDao paperDao;
    @Scheduled(cron = "0 0 0 1 * ?")
//    @Test
    public void myTask() throws IOException {
        Calendar calendar = Calendar.getInstance();
        int year = calendar.get(Calendar.YEAR);
        esUtil.deleteSelect();
        esUtil.creatESelect();
        esUtil.bulkImportSelections();
        LambdaQueryWrapper<Paper> lqw=new LambdaQueryWrapper<>();
        lqw.lt(Paper::getStartYear,year);
        Paper paper=new Paper();
        paper.setExpired((byte) 1);
        paperDao.update(paper,lqw);
    }
    @Scheduled(cron = "0 0 0 1 * ?")
//    @Test
    public void myTask2() throws IOException {
        Calendar calendar = Calendar.getInstance();
        int year = calendar.get(Calendar.YEAR);
        esUtil.deleteQuestion();
        esUtil.creatESQuestion();
        esUtil.bulkImportQuestion();
        LambdaQueryWrapper<Paper> lqw=new LambdaQueryWrapper<>();
        lqw.lt(Paper::getStartYear,year);
        Paper paper=new Paper();
        paper.setExpired((byte) 1);
        paperDao.update(paper,lqw);
    }
}
